package xyz.cerberu.cet.search.configuration;

import org.apache.solr.client.solrj.SolrClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import xyz.cerberu.cet.global.domain.Global;
import xyz.cerberu.cet.search.dao.SearchDao;
import xyz.cerberu.cet.search.server.SearchService;
import xyz.cerberu.cet.search.server.impl.SearchServiceImpl;
import xyz.cerberu.cet.search.server.impl.SolrSearchServiceImpl;

/**
 * @author β世界
 * Created on 9:13
 * @Description 用于管理搜索服务的注册
 */
@Configuration
public class SearchServiceConfig {
    private final Global global;

    @Autowired
    public SearchServiceConfig(Global global) {
        this.global = global;
    }

    /**
     * @author β世界 on 9:23 2021/3/19
     * 向容器中注入一个solr版本的搜索服务实现
     * @param solrClient: solr的客户端
     * @return xyz.cerberu.cet.search.server.SearchService
     **/
    @Bean
    @ConditionalOnProperty(name = {"global.search-living"},havingValue = "solr")
    public SearchService solrSearchService(SolrClient solrClient){
        return new SolrSearchServiceImpl(global,solrClient);
    }

    /**
     * @author β世界 on 9:24 2021/3/19
     * 向容器中注入最基本的搜索服务实现，是基于mysql的模糊查询和分词的实现
     * @param searchDao: 搜索的dao实现
     * @return xyz.cerberu.cet.search.server.SearchService
     **/
    @Bean
    @ConditionalOnProperty(name = {"global.search-living"},havingValue = "default")
    public SearchService searchService(SearchDao searchDao){
        return new SearchServiceImpl(searchDao);
    }

}
